<?php
/*! \brief
 * This is WFWidgetPoolManager class
 * This is the Class that manipulate WidgetPool event
 * \author William Su
 */
require_once dirname(__FILE__) . '/WidgetPoolManager.abstract.php';
class WFConfigureWidgetPoolManager extends AWidgetPoolManager
{
    public function __construct($objFramework){
        $strUpdateType = 'configure_widget';
        parent::__construct($objFramework, $strUpdateType);
    }
    /**
     *\brief Description
     * - Add /path/to/widget_news/widget/modNewWidget to /path/to/widgetPool/wpLogId/widget/.
     * - EX : Upgrade /path/to/widget_news/widget/modTodo which version is 2.0 to /path/to/widgetPool/wpLogId/widget/modTodo is 1.0
     * - Only widget_type=3 [configure widget] will move
     */
    protected function addOrUpgradeWidgetFromWidgetsNew(){
        $assocsConfigureWidgetFromWidgetsNew = $this->getAssocsConfigureWidgetFromWidgetsNew();
        $arrDir = array_keys($assocsConfigureWidgetFromWidgetsNew);
        if(is_array($arrDir) && $arrDir){
            foreach($arrDir as $strWidgetName){
                $strPathWidgetWPLogId = $this->getPathWPLogId() . '/widget/' . $strWidgetName;
                if(false === file_exists($strPathWidgetWPLogId)){
                    $this->addWidgetFromWidgetsNewByWidgetName($strWidgetName);
                }else{
                    $this->upgradeWidgetFromWidgetsNewByWidgetName($strWidgetName);
                }
            }
        }
        // move /path/to/widgets_new/widget/widget_info.xml to /path/to/repository/wigetPool/wpLogId
        $strPathSource = $this->getDocumentRootRelativePath().'/repository/widgets_new/widget/widget_info.xml';
        $strPathDest = $this->getPathWPLogIdRelativePath().'/widget/widget_info.xml';
        $this->objFramework->getIOFactory()->getFile()->copyRecurse($strPathSource, $strPathDest);
    }
    /**
     *\brief Description
     * - Add /path/to/widget_news/widgetComponent/comNewWidgetComponent to /path/to/widgetPool/wpLogId/widgetComponent/.
     * - EX : Upgrade /path/to/widget_news/widgetComponent/comTodo which version is 2.0 to /path/to/widgetPool/wpLogId/widgetComponent/comTodo is 1.0
     * - Due to this is the ConfigureWidgetPoolManager Class, so no need to do anything on widget component
     */
    protected function addOrUpgradeWidgetComponentFromWidgetsNew($mixProductId){
        // do nothing
    }
    /**
     * @see AWidgetPoolManager::updateSuccessResultToWidgetsNewInfoXml()
     *\brief Description
     * - update success status of widgets_new_info.xml => widget_update->widget_update_result=1
     */
    protected function updateSuccessResultToWidgetsNewInfoXml($mixProductId){
        $intUpdateResult = WFWidgetPoolOpt::WP_UPDATE_RESULT_UPDATE_SUCCESS;
        $this->objWidgetsNewInfoXmlManager->updateConfigureWidgetUpdateResultToWidgetsNewInfoXml($intUpdateResult);
    }
    /**
     * @see AWidgetPoolManager::updateFailedResultToWidgetsNewInfoXml()
     *\brief Description
     * - update failed status of widgets_new_info.xml => widget_update->widget_update_result=2
     */
    protected function updateFailedResultToWidgetsNewInfoXml($mixProductId){
        $intUpdateResult = WFWidgetPoolOpt::WP_UPDATE_RESULT_UPDATE_FAILED;
        $this->objWidgetsNewInfoXmlManager->updateConfigureWidgetUpdateResultToWidgetsNewInfoXml($intUpdateResult);
    }
}